Gradually Implementing CSS in Your Site
Table of Contents
Fixing Other Undesirable Attributes
Use the Dreamweaver Find and Replace command to remove all the other extraneous attributes from your layout, replacing them with rules instead. To achieve the maximum benefit of CSS in your designs, remove the following tags:
<br>tagsbgcolorandbackgroundattributesalignandvalignattributes- table attributes such as
borderandcellpadding
Optionally, you can remove the width attribute from <table> tags,
as well as the height attribute inside <td> tags.
However, you can also leave any or all of these attributes if you want
to ensure that your layout still renders well in older browsers. Adding
attributes to your CSS rules to replace these attributes is a
straightforward process; most attributes have a
similar name because you can find them in the CSS Styles dialog box.
Once you complete the styling of your document, you have one final step to achieve your goal. You need to move all the styles out of your document and place them in an external style sheet. Doing this lets you use the styles in other documents by linking to the style sheet.
Use the following steps to export styles:
- Return to the CSS Styles panel and right-click (Control-click on Mac) the style name.
- In the context menu, select Export.
- An Export Styles dialog box opens, asking you to specify a name for the new style sheet. Name the style sheet main.css and click OK.
- Although Dreamweaver exports the styles, they are still
in the document. To remove them from the document, select the
<style>tag in the CSS Styles panel and click the Trash icon in the lower right corner of the CSS Styles panel. - Click the Attach Style Sheet icon at the bottom of the CSS Styles panel and browse to your new external style sheet, main.css.
Voilà! You have now styled a page with CSS!
Now if you want to modify any of the styles, simply place your cursor in an element with the applied style and use the new Relevant CSS panel to modify the rule. You can find this panel by expanding the Tag Inspector panel and clicking the Relevant CSS tab. I like to work with this panel displaying a complete list of the attributes, so I click the Show List View button instead of the Show Category View button. This lists all the available CSS attributes for the selected rule.
Additionally, the top of the Relevant CSS panel displays the full cascade of styles applied all the way down to the selected style. At the top of the list, in blue, are the attributes which have a value in the selected rule. To add an attribute, simply locate it in the list and click the field to enter its value. Dreamweaver is smart enough to know that the style is actually in an external style sheet, so it opens the style sheet and modifies it. Because the style sheet is external to your document, Dreamweaver applies your modifications not only to the current document, but to all other documents in your site that link to it.
Next Steps
You've begun the journey toward a CSS-based website. I hope this article whetted your appetite for using CSS. Obviously, there is much more to learn. I encourage you to read the other great articles about CSS here on macromedia.com:
- An Overview of CSS in Dreamweaver MX 2004
- Designing with CSS in Dreamweaver MX 2004
- From Screen to Print: Creating a Print CSS
- Styled Headings for Authors and Users
Until next time, happy styling!